from datetime import datetime
from typing import Dict, Any, Optional
import uuid
from enum import Enum


class ContentType(str, Enum):
    TEXT = "text"
    IMAGE = "image"
    AUDIO = "audio"
    VIDEO = "video"


class Role(str, Enum):
    USER = "user"
    ASSISTANT = "assistant"
    SYSTEM = "system"


class ChatRecord:
    def __init__(
            self,
            user_id: str,
            saas_id: str,
            content_type: ContentType,
            content: str,
            role: Role,
            content_des: Optional[str] = None
    ):
        self.id = str(uuid.uuid4())
        self.user_id = user_id
        self.saas_id = saas_id
        self.content_type = content_type
        self.content = content
        self.role = role
        self.content_des = content_des
        self.timestamp = datetime.now().isoformat()

    def to_dict(self) -> Dict[str, Any]:
        return {
            "id": self.id,
            "user_id": self.user_id,
            "saas_id": self.saas_id,
            "content_type": self.content_type.value,
            "content": self.content,
            "role": self.role.value,
            "content_des": self.content_des,
            "timestamp": self.timestamp
        }

    @property
    def chat_content(self) -> str:
        if self.content_des:
            return f"{self.role}: {self.content} (描述: {self.content_des})"
        return f"{self.role}: {self.content}"